﻿using System;
using System.Collections.Generic;

namespace YArchitech.Plumbing
{
	public class IndoorSystem
	{
		public IndoorSystem()
		{
			this.circlePipes = new List<CirclePipe>();
			this.supplyMPipe = new HYPipeData();
			this.returnMPipe = new HYPipeData();
		}

		public IndoorSystem(IndoorSystem indoorSystem)
		{
			this.preSerialNum = indoorSystem.preSerialNum;
			this.serialNum = indoorSystem.serialNum;
			this.circleNum = indoorSystem.circleNum;
			this.circlePipes = this.InitialCirclePipes(indoorSystem.circlePipes);
			this.supplyMPipe = new HYPipeData(indoorSystem.supplyMPipe);
			this.returnMPipe = new HYPipeData(indoorSystem.returnMPipe);
			this.coeffReLocal = indoorSystem.coeffReLocal;
			this.resistanceLocal = indoorSystem.resistanceLocal;
			this.dPressControl = indoorSystem.dPressControl;
			this.dPressCapital = indoorSystem.dPressCapital;
			this.load = indoorSystem.load;
			this.flow = indoorSystem.flow;
			this.dPressDevise = indoorSystem.dPressDevise;
			this.pressCapital = indoorSystem.pressCapital;
			this.pressActual = indoorSystem.pressActual;
			this.rateUnbalance = indoorSystem.rateUnbalance;
		}

		private IList<CirclePipe> InitialCirclePipes(IList<CirclePipe> circlePipes)
		{
			IList<CirclePipe> list = new List<CirclePipe>();
			if (circlePipes == null || circlePipes.Count < 1)
			{
				return list;
			}
			foreach (CirclePipe circlePipe in circlePipes)
			{
				CirclePipe item = new CirclePipe(circlePipe);
				list.Add(item);
			}
			return list;
		}

		private double GetLoad()
		{
			double num = 0.0;
			if (this.CircleNum == 1)
			{
				num = this.CirclePipes[0].Load;
			}
			if (this.CircleNum > 1)
			{
				foreach (CirclePipe circlePipe in this.CirclePipes)
				{
					num += circlePipe.Load;
				}
				this.SupplyMPipe.Load = num;
				this.ReturnMPipe.Load = num;
			}
			return num;
		}

		private double GetFlow()
		{
			double num = 0.0;
			if (this.CircleNum == 1)
			{
				num = this.CirclePipes[0].Flow;
			}
			if (this.CircleNum > 1)
			{
				foreach (CirclePipe circlePipe in this.CirclePipes)
				{
					num += circlePipe.Flow;
				}
				this.SupplyMPipe.Load = num;
				this.ReturnMPipe.Load = num;
			}
			return num;
		}

		public string PreSerialNum
		{
			get
			{
				return this.preSerialNum;
			}
			set
			{
				this.preSerialNum = value;
			}
		}

		public string SerialNum
		{
			get
			{
				return this.serialNum;
			}
			set
			{
				this.serialNum = value;
			}
		}

		public virtual int CircleNum
		{
			get
			{
				return this.CirclePipes.Count;
			}
			set
			{
				this.circleNum = value;
			}
		}

		public virtual IList<CirclePipe> CirclePipes
		{
			get
			{
				return this.circlePipes;
			}
			set
			{
				this.circlePipes = value;
			}
		}

		public virtual HYPipeData SupplyMPipe
		{
			get
			{
				if (this.CircleNum > 1)
				{
					this.supplyMPipe.Load = 0.0;
					this.supplyMPipe.Flow = 0.0;
					foreach (CirclePipe circlePipe in this.CirclePipes)
					{
						this.supplyMPipe.Load += circlePipe.Load;
						this.supplyMPipe.Flow += circlePipe.Flow;
					}
				}
				if (this.supplyMPipe.Length == 0.0)
				{
					this.supplyMPipe.Length = 2.4;
				}
				if (string.IsNullOrEmpty(this.supplyMPipe.OutDiameter))
				{
					this.supplyMPipe.OutDiameter = ConstantOfGHCalc.XPAPWJB[2].ToString();
				}
				return this.supplyMPipe;
			}
			set
			{
				this.supplyMPipe = value;
			}
		}

		public virtual HYPipeData ReturnMPipe
		{
			get
			{
				if (this.CircleNum > 1)
				{
					this.returnMPipe.Load = 0.0;
					this.returnMPipe.Flow = 0.0;
					foreach (CirclePipe circlePipe in this.CirclePipes)
					{
						this.returnMPipe.Load += circlePipe.Load;
						this.returnMPipe.Flow += circlePipe.Flow;
					}
				}
				if (this.returnMPipe.Length == 0.0)
				{
					this.returnMPipe.Length = 2.4;
				}
				if (string.IsNullOrEmpty(this.returnMPipe.OutDiameter))
				{
					this.returnMPipe.OutDiameter = ConstantOfGHCalc.XPAPWJB[2].ToString();
				}
				return this.returnMPipe;
			}
			set
			{
				this.returnMPipe = value;
			}
		}

		public virtual double CoeffReLocal
		{
			get
			{
				return this.coeffReLocal;
			}
			set
			{
				this.coeffReLocal = value;
			}
		}

		public virtual double ResistanceLocal
		{
			get
			{
				return this.resistanceLocal;
			}
			set
			{
				this.resistanceLocal = value;
			}
		}

		public virtual double DPressControl
		{
			get
			{
				return this.dPressControl;
			}
			set
			{
				this.dPressControl = value;
			}
		}

		public virtual double DPressCapital
		{
			get
			{
				return this.dPressCapital;
			}
			set
			{
				this.dPressCapital = value;
			}
		}

		public virtual double Load
		{
			get
			{
				return this.GetLoad();
			}
			set
			{
				this.load = value;
			}
		}

		public virtual double Flow
		{
			get
			{
				return this.GetFlow();
			}
			set
			{
				this.flow = value;
			}
		}

		public virtual double DPressDevise
		{
			get
			{
				return this.dPressDevise;
			}
			set
			{
				this.dPressDevise = value;
			}
		}

		public virtual double PressCapital
		{
			get
			{
				return this.pressCapital;
			}
			set
			{
				this.pressCapital = value;
			}
		}

		public virtual double PressActual
		{
			get
			{
				return this.pressActual;
			}
			set
			{
				this.pressActual = value;
			}
		}

		public double RateUnbalance
		{
			get
			{
				return this.rateUnbalance;
			}
			set
			{
				this.rateUnbalance = value;
			}
		}

		private string preSerialNum;

		private string serialNum;

		private int circleNum;

		private IList<CirclePipe> circlePipes;

		private HYPipeData supplyMPipe;

		private HYPipeData returnMPipe;

		private double coeffReLocal;

		private double resistanceLocal;

		private double dPressControl;

		private double dPressCapital;

		private double load;

		private double flow;

		private double dPressDevise;

		private double pressCapital;

		private double pressActual;

		private double rateUnbalance;
	}
}
